#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

class MinStack 
{
public:
	MinStack(){}
	void push(int val)
	{
		v.push_back(val);
	}
	void pop()
	{
		v.pop_back();
	}
	int top()
	{
		return v.back();
	}
	int getMin()
	{
		int min = v.front();
		for (auto e : v)
		{
			if (e < min)
			{
				min = e;
			}
		}
		return min;
	}
	bool empty()
	{
		return !v.size();
	}
private:
	vector<int> v;
};

void test5()
{
	int t;
	cin >> t;
	MinStack ms;
	while (t--)
	{
		char ch;
		cin >> ch;
		if (ch == 'P')
		{
			int x;
			cin >> x;
			ms.push(x);
			cout << ms.getMin();
			if (t)
			{
				cout << endl;
			}
		}
		else if (ch == 'T' && !ms.empty())
		{
			cout << ms.top() << ' ' << ms.getMin();
			if (t)
			{
				cout << endl;
			}
		}
		else if (ch == 'O' && !ms.empty())
		{
			ms.pop();
			cout << ms.getMin();
			if (t)
			{
				cout << endl;
			}
		}
		else
		{
			cout << ms.getMin();
			if (t)
			{
				cout << endl;
			}
		}
	}
}

int main()
{
	test5();
	return 0;
}
